package org.blogwu.learn.arithmetic.demo1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;

public class Solution {

    public static void main(String[] args) {
        {
            // 1
            int[] tex = {3, 2, 1};
            System.out.println(thirdMax4(tex));
            System.out.println("-------------------");
        }
        {
            // 2
            int[] tex = {3, 2, 1, 4};
            System.out.println(thirdMax4(tex));
            System.out.println("-------------------");
        }
        //[2,2,3,1]
        {
            // 2
            int[] tex = {2, 2, 3, 1};
            System.out.println(thirdMax4(tex));
            System.out.println("-------------------");
        }
        {
            // 2
            int[] tex = {2, 2, 3, 1, 1};
            System.out.println(thirdMax4(tex));
            System.out.println("-------------------");
        }
        {
            // 2
            int[] tex = {1, 1, 2};
            System.out.println(thirdMax4(tex));
            System.out.println("-------------------");
        }
    }

    public static int thirdMax5(int[] nums) {
        if (nums.length == 1) return nums[0];
        List st = new ArrayList(3);
        return 0;
    }

    public static int thirdMax4(int[] nums) {
        if (nums.length == 1) return nums[0];
        List st = new ArrayList(3);
        for (int i = 0; i < nums.length; i++) {
            if (st.isEmpty()) {
                st.add(nums.length);
                continue;
            }
            int value = nums[i];
            if (st.indexOf(value) > 0) {
                continue;
            }
            for (int j = 0; j < st.size(); j++) {
                int new1 = (int) st.get(j);
                if (value > new1) {
                    st.set(j, value);
                    if (j - 1 >= 0) {
                        st.set(j - 1, new1);
                    }
                }
            }
        }
        System.out.println(Arrays.toString(st.toArray()));
        return 0;
    }

    public static int thirdMax3(int[] nums) {
        if (nums.length == 1) return nums[0];
        Stack st = new Stack();
        Stack stemp = new Stack();
        for (int i = 0; i < nums.length; i++) {
            if (st.empty()) {
                st.push(nums[i]);
                continue;
            }
            if (st.search(nums[i]) > 0) {
                continue;
            }


        }

        return 0;
    }


    public static int thirdMax(int[] nums) {
        if (nums.length == 1) return nums[0];
        int[] neccx = {-1, -1, -1};
        for (int i = 0; i < nums.length; i++) {
            int indexValue = nums[i];
            if (indexValue >= neccx[0]) {
                neccx[0] = indexValue;
                if (indexValue >= neccx[1]) {
                    neccx[0] = neccx[1];
                    neccx[1] = indexValue;
                    if (indexValue >= neccx[2]) {
                        neccx[1] = neccx[2];
                        neccx[2] = indexValue;
                        continue;
                    }
                }
            }
        }
        System.out.println("Arrays:" + Arrays.toString(neccx));
        if (nums.length == 2) {
            return neccx[2];
        } else {
            return neccx[0];
        }
    }


    public static int thirdMax2(int[] nums) {
        if (nums.length == 1) return nums[0];
        int[] neccx = {-1, -1, -1};
        for (int i = 0; i < nums.length; i++) {
            int indexValue = nums[i];
            if (indexValue >= neccx[0]) {
                int temp = neccx[0];
                neccx[0] = indexValue;
                if (indexValue >= neccx[1]) {
                    int temp2 = neccx[1];

                    neccx[0] = neccx[1];
                    if (indexValue == neccx[1]) {
                        neccx[0] = temp;
                    }
                    neccx[1] = indexValue;
                    if (indexValue >= neccx[2]) {
                        neccx[1] = neccx[2];
                        if (indexValue == neccx[2]) {
                            neccx[0] = temp;
                            neccx[1] = temp2;
                        }
                        neccx[2] = indexValue;
                        continue;
                    }
                }
            }
        }
        System.out.println("Arrays:" + Arrays.toString(neccx));
        if (nums.length == 2) {
            return neccx[2];
        }
        for (int i = 0; i < neccx.length; i++) {
            if (neccx[i] < 0) {
                return neccx[2];
            }
        }
        return neccx[0];
    }
    //1 ,2,5


    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> wb = new ArrayList<List<Integer>>(numRows);
        for (int i = 0; i < numRows; i++) {
            List<Integer> nn = new ArrayList<Integer>(i + 1);
        }


        return null;
    }
}
